package tech.yunland.shop.domain.model.report;

import com.alibaba.fastjson.annotation.JSONField;
import com.moyuer.bsf.domain.model.AbstractVersionEntity;
import com.moyuer.bsf.domain.model.User;
import com.moyuer.bsf.domain.model.UserRoles;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.apache.commons.lang3.StringUtils;

import tech.yunland.shop.domain.model.GoodsPictures;
import tech.yunland.shop.domain.model.TagGoods;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * 销售提成明细
 *
 * @author 王睿智<geekrize@gmail.com> 16/5/27
 */

@Entity
@Table(name = "rpt_commission")
public class Commission extends AbstractVersionEntity {

	@JSONField(format = "yyyy-MM-dd")
	@Column(name = "biz_date")
	private Date bizDate = new Date(); // 报表日期



	@Column(name = "organ_id")
	private String organId; // 所属机构

	@JSONField(serialize = false)
	@ManyToOne
	private User user;// 员工

	private BigDecimal sale = BigDecimal.ZERO; // 销售总额

	private BigDecimal charge = BigDecimal.ZERO; // 充值总额

	private BigDecimal commission = BigDecimal.ZERO; // 提成总额

	@Transient
	private String userName;

	@Transient
	private String userId;

	@Transient
	private String roleName;

	@Transient
	private String pictureName;

	// userId
	public String getUserId() {
		if (this.userId != null) {
			return this.userId;
		}
		if(user!=null){
			this.userId=this.user.getId();
		}
		return userId;
	}

	public void setUserId(String userId) {
		this.userId = userId;
	}

	// picture
	public String getPictureName() {
		if (this.pictureName != null) {
			return this.pictureName;
		}
		return this.user.getPortraitName();
	}

	public void setPictureName(String PictureName) {
		this.pictureName = PictureName;
	}

	public String getUserName() {
		return user.getName();
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public String getRoleName() {
		if (this.user != null) {
			List roleNames = new ArrayList();
			for (UserRoles userRoles : this.user.getUserRoles()) {
				roleNames.add(userRoles.getRole().getName());
			}
			this.roleName = StringUtils.join(roleNames, ",");
		}
		return this.roleName;
	}

	public void setRoleName(String roleName) {
		this.roleName = roleName;
	}

	public Date getBizDate() {
		return bizDate;
	}

	public void setBizDate(Date bizDate) {
		this.bizDate = bizDate;
	}

	public String getOrganId() {
		return organId;
	}

	public void setOrganId(String organId) {
		this.organId = organId;
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public BigDecimal getSale() {
		return sale == null ? BigDecimal.ZERO : sale;
	}

	public void setSale(BigDecimal sale) {
		this.sale = sale;
	}

	public BigDecimal getCharge() {
		return charge == null ? BigDecimal.ZERO : charge;
	}

	public void setCharge(BigDecimal charge) {
		this.charge = charge;
	}

	public BigDecimal getCommission() {
		return commission == null ? BigDecimal.ZERO : commission;
	}

	public void setCommission(BigDecimal commission) {
		this.commission = commission;
	}

}
